#include "mainwindow.h"
#include <QDebug>

MainWindow::MainWindow(QWidget* parent)
    : QMainWindow(parent)
{
    // 设置窗口标题和大小
    setWindowTitle("方向控制按钮");
    resize(400, 900);
    // 设置主窗口的背景颜色为黑色
    this->setStyleSheet("background-color: black;");

    // 创建中央部件
    QWidget* centralWidget = new QWidget(this);
    setCentralWidget(centralWidget);

    // 创建网格布局
    QGridLayout* layout = new QGridLayout(centralWidget);

    // 上下左右左右平移

    // 创建四个方向的按钮
    ArrowButton* upBtn = new ArrowButton(ArrowDirection::Up, this);
    upBtn->setArrowColor(Qt::white);
    upBtn->setBorderColor(Qt::white);
    ArrowButton* downBtn = new ArrowButton(ArrowDirection::Down, this);
    downBtn->setArrowColor(Qt::white);
    downBtn->setBorderColor(Qt::white);
    ArrowButton* leftBtn = new ArrowButton(ArrowDirection::Left, this);
    leftBtn->setArrowColor(Qt::white);
    leftBtn->setBorderColor(Qt::white);
    ArrowButton* rightBtn = new ArrowButton(ArrowDirection::Right, this);
    rightBtn->setArrowColor(Qt::white);
    rightBtn->setBorderColor(Qt::white);
    ArrowButton* leftShiftBtn = new ArrowButton(ArrowDirection::LeftShift, this);
    leftShiftBtn->setArrowColor(Qt::white);
    leftShiftBtn->setBorderColor(Qt::white);
    ArrowButton* rightShiftBtn = new ArrowButton(ArrowDirection::RightShift, this);
    rightShiftBtn->setArrowColor(Qt::white);
    rightShiftBtn->setBorderColor(Qt::white);


    // 将按钮添加到网格布局中（形成十字形布局）
    layout->addWidget(leftShiftBtn, 0, 0, Qt::AlignCenter);
    layout->addWidget(upBtn, 0, 1, Qt::AlignCenter);    // 第一行，第二列（上）
    layout->addWidget(rightShiftBtn, 0, 2, Qt::AlignCenter);
    layout->addWidget(leftBtn, 1, 0, Qt::AlignCenter);  // 第二行，第一列（左）
    layout->addWidget(rightBtn, 1, 2, Qt::AlignCenter); // 第二行，第三列（右）
    layout->addWidget(downBtn, 2, 1, Qt::AlignCenter);  // 第三行，第二列（下）

    // 上下左右开合关闭

    openBtn = new OpenCloseButton(OpenCloseType::Open, this);
    openBtn->setArrowColor(Qt::white);
    openBtn->setBorderColor(Qt::white);
    closeBtn = new OpenCloseButton(OpenCloseType::Close, this);
    closeBtn->setArrowColor(Qt::white);
    closeBtn->setBorderColor(Qt::white);
    stretchBtn = new OpenCloseButton(OpenCloseType::Stretch, this);
    stretchBtn->setArrowColor(Qt::white);
    stretchBtn->setBorderColor(Qt::white);
    compressBtn = new OpenCloseButton(OpenCloseType::Compress, this);
    compressBtn->setArrowColor(Qt::white);
    compressBtn->setBorderColor(Qt::white);

    layout->addWidget(openBtn, 3, 0, Qt::AlignCenter);
    layout->addWidget(closeBtn, 3, 1, Qt::AlignCenter);
    layout->addWidget(stretchBtn, 4, 0, Qt::AlignCenter);
    layout->addWidget(compressBtn, 4, 1, Qt::AlignCenter);


    // 顺逆时针

    clockwiseBtn = new RotateButton(RotateDirection::Clockwise, this);
    clockwiseBtn->setArrowColor(Qt::white);
    clockwiseBtn->setBorderColor(Qt::white);
    counterClockwiseBtn = new RotateButton(RotateDirection::CounterClockwise, this);
    counterClockwiseBtn->setArrowColor(Qt::white);
    counterClockwiseBtn->setBorderColor(Qt::white);

    layout->addWidget(clockwiseBtn, 5, 0, Qt::AlignCenter);
    layout->addWidget(counterClockwiseBtn, 5, 1, Qt::AlignCenter);

    /// 加号减号
    plusBtn = new PlusMinusButton(PlusMinuType::Plus, this);
    plusBtn->setBorderColor(Qt::white);
    plusBtn->setSymbolColor(Qt::white);
    minusBtn = new PlusMinusButton(PlusMinuType::Minus, this);
    minusBtn->setBorderColor(Qt::white);
    minusBtn->setSymbolColor(Qt::white);
    layout ->addWidget(plusBtn, 6, 0, Qt::AlignCenter);
    layout ->addWidget(minusBtn, 6, 1, Qt::AlignCenter);


    // 设置布局的边距和间距
    layout->setContentsMargins(20, 20, 20, 20);
    layout->setSpacing(10);

    // 连接按钮的点击信号到槽函数
    connect(upBtn, &ArrowButton::clicked, this, &MainWindow::onUpClicked);
    connect(downBtn, &ArrowButton::clicked, this, &MainWindow::onDownClicked);
    connect(leftBtn, &ArrowButton::clicked, this, &MainWindow::onLeftClicked);
    connect(rightBtn, &ArrowButton::clicked, this, &MainWindow::onRightClicked);
}

MainWindow::~MainWindow()
{
}

void MainWindow::onUpClicked()
{
    qDebug() << "向上按钮被点击";
    // 这里可以添加向上移动的逻辑
}

void MainWindow::onDownClicked()
{
    qDebug() << "向下按钮被点击";
    // 这里可以添加向下移动的逻辑
}

void MainWindow::onLeftClicked()
{
    qDebug() << "向左按钮被点击";
    // 这里可以添加向左移动的逻辑
}

void MainWindow::onRightClicked()
{
    qDebug() << "向右按钮被点击";
    // 这里可以添加向右移动的逻辑
}